package cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdx;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdx.vo.GiItemDxPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdx.vo.GiItemDxRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdx.vo.GiItemDxSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.giitem.GiItemDxDO;
import cn.iocoder.yudao.module.erp.service.giitem.GiItemDxService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - ERP物流东线口岸仓库货号详情")
@RestController
@RequestMapping("/erp/gi-item-dx")
@Validated
public class GiItemDxController {

    @Resource
    private GiItemDxService giItemDxService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP物流东线口岸仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dx:create')")
    public CommonResult<Long> createGiItemDx(@Valid @RequestBody GiItemDxSaveReqVO createReqVO) {
        return success(giItemDxService.createGiItemDx(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP物流东线口岸仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dx:update')")
    public CommonResult<Boolean> updateGiItemDx(@Valid @RequestBody GiItemDxSaveReqVO updateReqVO) {
        giItemDxService.updateGiItemDx(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP物流东线口岸仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dx:delete')")
    public CommonResult<Boolean> deleteGiItemDx(@RequestParam("id") Long id) {
        giItemDxService.deleteGiItemDx(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP物流东线口岸仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dx:query')")
    public CommonResult<GiItemDxRespVO> getGiItemDx(@RequestParam("id") Long id) {
        GiItemDxDO giItemDx = giItemDxService.getGiItemDx(id);
        return success(BeanUtils.toBean(giItemDx, GiItemDxRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP物流东线口岸仓库货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dx:query')")
    public CommonResult<PageResult<GiItemDxRespVO>> getGiItemDxPage(@Valid GiItemDxPageReqVO pageReqVO) {
        PageResult<GiItemDxDO> pageResult = giItemDxService.getGiItemDxPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GiItemDxRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP物流东线口岸仓库货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dx:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportGiItemDxExcel(@Valid GiItemDxPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GiItemDxDO> list = giItemDxService.getGiItemDxPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP物流东线口岸仓库货号详情.xls", "数据", GiItemDxRespVO.class,
                        BeanUtils.toBean(list, GiItemDxRespVO.class));
    }

}